package com.eleadmin.common.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eleadmin.common.core.web.PageResult;
import com.eleadmin.common.system.entity.Goods;
import com.eleadmin.common.system.mapper.GoodsMapper;
import com.eleadmin.common.system.param.GoodsParam;
import com.eleadmin.common.system.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;


    @Override
    public PageResult<Goods> showGoods(GoodsParam goodsParam) {
        //构造查询条件
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();

        //分页
        Page<Goods> page = new Page<>(goodsParam.getPageNum(), goodsParam.getPageSize());

        Page<Goods> goodsPage = goodsMapper.selectPage(page,queryWrapper);
        List<Goods> goodsList = goodsPage.getRecords();
        long totalCount = goodsPage.getTotal();

        PageResult<Goods> pageResult = new PageResult<>(goodsList, totalCount);

        return pageResult;
    }
}











